<!-- forget_password -->
<template>
  <div class="app_contain">
    <div class="contain">
      <header></header>
      <div class="center">
        <div class="login_card">
          <img src="@/assets/img/logo.svg" alt="logo" />
          <el-steps :active="0" finish-status="success" align-center>
            <el-step title="选择账户"></el-step>
            <el-step title="安全验证"></el-step>
          </el-steps>
          <div class="tip_text">邮箱或手机号</div>
          <el-input placeholder="请输入账号" v-model="account" hidden  autocomplete="new-password"> </el-input>

          <div class="login_btn_contain" @click="next">下一步</div>
        </div>
      </div>
      <footer></footer>
    </div>
  </div>
</template>

<script>
import { test_account_phone, test_account_email } from "../../api/login";
export default {
  name: "forget_password",
  data() {
    return {
      check_account_phone:
        /^(13[0-9]|14[5|7]|15[0|1|2|3|4|5|6|7|8|9]|18[0|1|2|3|5|6|7|8|9])\d{8}$/,
      check_account_email: /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/,
      account: "",
    };
  },
  methods: {
    next() {
      if (
        this.check_account_phone.test(this.account) &&
        this.account.length === 11
      ) {
        test_account_phone(this.account)
          .then((response) => {
            if (response.data.message === "手机号码已被使用，请尝试找回密码") {
              sessionStorage.setItem(
                "forget_password_user_info",
                JSON.stringify({ account: this.account })
              );
              this.$router.push("/forget_password_captcha");
            } else {
              this.$message({
                message: "该账号未注册",
                type: "warning",
              });
            }
          })
          .catch((error) => {});
      } else if (this.check_account_email.test(this.account)) {
        test_account_email(this.account).then((data) => {
          if (data.data.message === "邮箱地址已被使用，请尝试找回密码") {
            sessionStorage.setItem(
              "forget_password_user_info",
              JSON.stringify({ account: this.account })
            );
            this.$router.push("/forget_password_captcha");
          } else {
            this.$message({
              message: "该账号未注册",
              type: "warning",
            });
          }
        });
      } else {
        this.$message({
          message: "账号格式不对",
          type: "warning",
        });
      }
    },
  },
};
</script>

<style lang='scss' scoped>
@import "@/assets/css/login.scss";
.tip_text {
  color: rgba(0, 0, 0, 0.6);
}
.el-input {
  margin-top: 6px !important;
}
</style>